package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 商场管理的品牌制造商
 */

@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    /**
     * 品牌制造商首页
     * @return 返回所有的brand
     */
    @RequestMapping("list")
    public BaseRespVo brandList(Integer page, Integer limit, String sort, String order, Integer id, String name){
        ItemsListVO<Brand> brandListVO = brandService.queryBrandList(page, limit, sort, order, id, name);
        return BaseRespVo.ok(brandListVO);
    }


    /**
     * 新增品牌制造商
     * @return 包含新增的brand数据的BaseRespVo
     */
    @RequestMapping("create")
    public BaseRespVo createBrand(@RequestBody Brand brand){
        Brand newBrand = brandService.createBrand(brand);
        return BaseRespVo.ok(newBrand);
    }

    /**
     * 更新品牌制造商
     * @return 包含更新的brand数据的BaseRespVo
     */
    @RequestMapping("update")
    public BaseRespVo updateBrand(@RequestBody Brand brand){
        Brand updateBrand = brandService.updateBrand(brand);
        return BaseRespVo.ok(updateBrand);
    }

    /**
     * 删除品牌制造商
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo deleteBrand(@RequestBody Brand brand){
        int delete = brandService.deleteBrand(brand);
        if (delete == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败");
    }
}
